package com.edais.actions;

import java.io.Serializable;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.edais.service.KcodeService;
import com.edais.util.IsObjNullUtil;
import com.edais.util.LianlianPayUtil;
import com.edais.util.Md5SignatureUtil;
import com.edais.vo.ChannelConstans;
import com.edais.vo.ResultMsgVo;

/**
 * 
 * ClassName: WeixinLDKcodeAction.java
 * 
 * @Description: 渲云&&麦田 接口
 * @author ruXinChao
 * @date 2016-9-14 下午2:30:49
 */
@Controller
@RequestMapping("/kcode")
public class KcodeAction implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static final Log logger = LogFactory.getLog(KcodeAction.class);

	@Autowired
	private KcodeService kcodeService;

	/**
	 * 
	 * @Description: 发送K码资格验证
	 * @param request
	 * @param response
	 * @return
	 * @return ResultMsgVo<Object>
	 * @author ruXinChao
	 * @date 2016-9-14 下午3:53:15
	 */

	@RequestMapping(value = "/validate", method = RequestMethod.POST)
	@ResponseBody
	public ResultMsgVo<Object> validate(HttpServletRequest request,
			HttpServletResponse response) {

		logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>渲云接口检测K码发送资格<<<<<<<<<<<<<<<<<<<<<<<<<<<<");

		ResultMsgVo<Object> rmv = new ResultMsgVo<Object>();

		// 读取request的流
		String reqString = LianlianPayUtil.readReqStr(request);

		if (StringUtils.isBlank(reqString)) {
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：未输入参数");
			return rmv;
		}

		JSONObject jsonObj=null;
		try {
			/** 获得参数以及检查参数 **/
			 jsonObj = JSONObject.fromObject(reqString);
		} catch (Exception e) {
			
			logger.info("校验参数失败，参数格式错误。实际参数"
					+ reqString);
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：缺少参数");
			return rmv;
		}

		List<String> keyList = Arrays.asList("mobile", "userId", "merchant",
				"signType", "sign");

		if (this.checkJsonKey(jsonObj, keyList)) {
			logger.info("校验参数失败，缺少参数应有参数{mobile, userId,merchant,signType,sign}实际参数"
					+ reqString);
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：缺少参数");
			return rmv;
		}

		String mobile = jsonObj.getString("mobile");// 手机号
		String userId = jsonObj.getString("userId");// 用户ID
		String merchant = jsonObj.getString("merchant");// 商户（xuanyun）
		String signType = jsonObj.getString("signType");// 签名类型（MD5）
		String sign = jsonObj.getString("sign");// 签名字符

		String logInfo = "检验K码发送资格userId=" + userId;
		logger.info(logInfo + "1、请求参数" + reqString);

		/** 校验MD5签名 **/
		try {

			if (IsObjNullUtil.isEmpty(mobile, userId, merchant, signType, sign)) {
				logger.info(logInfo + "2、校验参数失败" + reqString);
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
				rmv.setmessage("参数校验失败：参数有空值");
				return rmv;
			}

			if (!IsObjNullUtil.isMobileNO(mobile)) {
				logger.info(logInfo + "校验参数失败,手机号输入有误" + reqString);
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
				rmv.setmessage("参数校验失败：手机号格式错误");
				return rmv;
			}
			if (!"xuanyun".equals(merchant)) {
				logger.info(logInfo + "校验参数失败,商户错误，应为xuanyun" + reqString);
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
				rmv.setmessage("参数校验失败：渠道错误");
				return rmv;
			}

			logger.info(logInfo + "3、开始验签");
			if (!Md5SignatureUtil.checkSign(reqString, null,
					kcodeService.getSecretKey(ChannelConstans.XY_CHANNEL_ID))) { // 22代表渲云的渠道id
				logger.error(logInfo + "验签失败");
				rmv.setRescode(ResultMsgVo.RESCODE_1000);// 验证签名失败
				return rmv;
			}
		} catch (Exception e) {
			logger.error(logInfo + "验证签名异常", e);
			rmv.setRescode(ResultMsgVo.RESCODE_1000);// 验证签名失败
			return rmv;
		}
		logger.info(logInfo + "验签成功");

		try {
			logger.info(logInfo + "4、开始验证是否有资格");
			String resultCode = kcodeService.checkKcode(mobile, userId,
					merchant);

			rmv.setRescode(resultCode);
		} catch (Exception e) {
			logger.error(logInfo + "发送K码资格验证异常", e);
			rmv.setRescode(ResultMsgVo.RESCODE_3000);
		}

		logger.info(logInfo + "返回值为" + JSONObject.fromObject(rmv).toString());
		return rmv;
	}

	/**
	 * 
	 * @Description: 发送k码
	 * @param request
	 * @param response
	 * @return
	 * @return ResultMsgVo<Object>
	 * @author ruXinChao
	 * @date 2016-9-14 下午5:16:03
	 */
	@RequestMapping(value = "/sendKcode", method = RequestMethod.POST)
	@ResponseBody
	public ResultMsgVo<Object> sendKcode(HttpServletRequest request,
			HttpServletResponse response) {
		logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>渲云接口发送K码<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
		ResultMsgVo<Object> rmv = new ResultMsgVo<Object>();
		// 读取request的流
		String reqString = LianlianPayUtil.readReqStr(request);
		logger.info("发送k码: " + reqString);

		/** 检验参数 **/
		if (StringUtils.isBlank(reqString)) {
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：未输入参数");
			return rmv;
		}

		JSONObject jsonObj=null;
		try {
			/** 获得参数以及检查参数 **/
			 jsonObj = JSONObject.fromObject(reqString);
		} catch (Exception e) {
			logger.info("校验参数失败，参数格式错误。实际参数"
					+ reqString);
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：缺少参数");
			return rmv;
		}

		List<String> keyList = Arrays.asList("merchant", "signType", "sign",
				"orderId", "mobile", "userId", "money");

		if (this.checkJsonKey(jsonObj, keyList)) {
			logger.info("校验参数失败，缺少参数应有参数{merchant, signType,sign,orderId,mobile,userId,money}实际参数"
					+ reqString);
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败\
			rmv.setmessage("参数校验失败：缺少参数");
			return rmv;
		}

		String merchant = jsonObj.getString("merchant");// 商户（xuanyun）
		String signType = jsonObj.getString("signType");// 签名类型（MD5）
		String sign = jsonObj.getString("sign");// 签名字符
		String orderId = jsonObj.getString("orderId");// 订单id
		String mobile = jsonObj.getString("mobile");// 手机号码
		String userId = jsonObj.getString("userId");// 平台用户id
		String money = jsonObj.getString("money");// 金额(两位小数)

		String logInfo = "发送K码" + orderId + "-";

		/** 校验MD5签名 **/
		try {
			// 校验必填参数
			if (IsObjNullUtil.isEmpty(mobile, userId, merchant, signType, sign,
					money, orderId)) {
				logger.info(logInfo + "返回值为"
						+ JSONObject.fromObject(rmv).toString());
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
				rmv.setmessage("参数校验失败：参数有空值");
				return rmv;
			}
			
			double rmb = Double.parseDouble(money);
			if (rmb < 300) {
				logger.info(logInfo + "金额小于300");
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
				rmv.setmessage("参数校验失败：金额小于300");
				logger.info(logInfo + "返回值为"
						+ JSONObject.fromObject(rmv).toString());
				return rmv;
			}

			if (!IsObjNullUtil.isMobileNO(mobile)) {
				logger.info(logInfo + "校验参数失败,手机号输入有误" + reqString);
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败、
				rmv.setmessage("参数校验失败：手机号格式错误");
				return rmv;
			}
			if (!"xuanyun".equals(merchant)) {
				logger.info(logInfo + "校验参数失败,商户错误，应为xuanyun" + reqString);
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
				rmv.setmessage("参数校验失败：渠道错误");
				return rmv;
			}

			if (!Md5SignatureUtil.checkSign(reqString, null,
					kcodeService.getSecretKey(ChannelConstans.XY_CHANNEL_ID))) {// 22代表渲云的渠道id
				rmv.setRescode(ResultMsgVo.RESCODE_1000);// 验证签名失败
				logger.error(logInfo + "验签失败");
				logger.info(logInfo + "返回值为"
						+ JSONObject.fromObject(rmv).toString());
				return rmv;
			}
		} catch (Exception e) {
			logger.error(logInfo + "验证签名异常", e);
			rmv.setRescode(ResultMsgVo.RESCODE_1000);// 验证签名失败
			logger.info(logInfo + "返回值为"
					+ JSONObject.fromObject(rmv).toString());
			return rmv;
		}
		logger.error(logInfo + "验签成功");
		String cardNo = null;
	

		logger.info(logInfo + "参数验证成功");
		try {
			/** 1.检验发送资格 **/
			String resultCode = kcodeService.sendCheckKcode(mobile, userId,
					merchant, orderId);
			if (!ResultMsgVo.RESCODE_0000.equals(resultCode)) {
				rmv.setRescode(resultCode);
				logger.info(logInfo + "检验发送资格失败" + resultCode);
				logger.info(logInfo + "返回值为"
						+ JSONObject.fromObject(rmv).toString());
				return rmv;
			}
			logger.info(logInfo + "检验发送资格成功");
			/** 2更新，并获得cardNo **/
			Map<String, Object> resultMap = kcodeService.updateStatus(merchant,
					userId, mobile, orderId, money);

			String rescode = (String) resultMap.get("rescode");
			if (!ResultMsgVo.RESCODE_0000.equals(rescode)) {
				rmv.setRescode(rescode);
				logger.info(logInfo + "获取K号失败");
				logger.info(logInfo + "返回值为"
						+ JSONObject.fromObject(rmv).toString());
				return rmv;
			}
			cardNo = (String) resultMap.get("cardNo");
		} catch (Exception e) {
			logger.error(logInfo + "获取K号异常", e);
			rmv.setRescode(ResultMsgVo.RESCODE_3000);
			logger.info(logInfo + "返回值为"
					+ JSONObject.fromObject(rmv).toString());
			logger.info(logInfo + "返回值为"
					+ JSONObject.fromObject(rmv).toString());
			return rmv;
		}

		/** 1.发送K码，并更新K码记录表 **/
		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			String resultCode = kcodeService.sendKcode(logInfo, merchant,
					mobile, orderId, cardNo);
			if (!ResultMsgVo.RESCODE_0000.equals(resultCode)) {// 发送K码失败
				rmv.setRescode(resultCode);
				return rmv;
			}
			// 查询
			resultMap = kcodeService.queryResult(merchant, orderId);

		} catch (Exception e) {
			logger.error(logInfo + "发送K码异常", e);
			rmv.setRescode(ResultMsgVo.RESCODE_3000);
			return rmv;
		}

		rmv.setRescode(ResultMsgVo.RESCODE_0000);
		rmv.setData(resultMap);
		logger.info(logInfo + "返回值为" + JSONObject.fromObject(rmv).toString());
		return rmv;
	}

	/**
	 * 
	 * @Description: 查询K码发送结果
	 * @param request
	 * @param response
	 * @return
	 * @return ResultMsgVo<Object>
	 * @author ruXinChao
	 * @date 2016-9-14 下午5:16:47
	 */

	@RequestMapping(value = "/queryResult", method = RequestMethod.POST)
	@ResponseBody
	public ResultMsgVo<Object> queryResult(HttpServletRequest request,
			HttpServletResponse response) {
		logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>渲云接口查询K码发送结果<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
		ResultMsgVo<Object> rmv = new ResultMsgVo<Object>();

		// 读取request的流
		String reqString = LianlianPayUtil.readReqStr(request);

		/** 检验参数 **/
		if (StringUtils.isBlank(reqString)) {
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：未输入参数");
			return rmv;
		}

		JSONObject jsonObj=null;
		try {
			/** 获得参数以及检查参数 **/
			 jsonObj = JSONObject.fromObject(reqString);
		} catch (Exception e) {
			logger.info("校验参数失败，参数格式错误。实际参数"
					+ reqString);
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：缺少参数");
			return rmv;
		}

		List<String> keyList = Arrays.asList("merchant", "signType", "sign",
				"orderId");

		if (this.checkJsonKey(jsonObj, keyList)) {
			logger.info("校验参数失败，缺少参数应有参数{merchant, signType,sign,orderId}实际参数"
					+ reqString);
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：缺少参数");
			return rmv;
		}

		String merchant = jsonObj.getString("merchant");// 商户（xuanyun）
		String signType = jsonObj.getString("signType");// 签名类型（MD5）
		String sign = jsonObj.getString("sign");// 签名字符
		String orderId = jsonObj.getString("orderId");// 订单id

		String logInfo = "查询K码发送结果" + orderId + "-";
		logger.info(logInfo + "1.请求参数" + reqString);

		logger.info(logInfo + "2.检测参数开始");

		/** 校验MD5签名 **/
		try {

			// 校验必填参数
			if (IsObjNullUtil.isEmpty(merchant, signType, sign, orderId)) {
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
				rmv.setmessage("参数校验失败：参数有空值");
				logger.info(logInfo + "返回值为"
						+ JSONObject.fromObject(rmv).toString());
				return rmv;
			}

			if (!"xuanyun".equals(merchant)) {
				logger.info(logInfo + "校验参数失败,商户错误，应为xuanyun" + reqString);
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
				rmv.setmessage("参数校验失败：渠道错误");
				return rmv;
			}

			if (!Md5SignatureUtil.checkSign(reqString, null,
					kcodeService.getSecretKey(ChannelConstans.XY_CHANNEL_ID))) {// 22代表渲云的渠道id
				rmv.setRescode(ResultMsgVo.RESCODE_1000);// 验证签名失败

				logger.error(logInfo + "验签失败");
				logger.info(logInfo + "返回值为"
						+ JSONObject.fromObject(rmv).toString());
				return rmv;
			}
		} catch (Exception e) {
			logger.error(logInfo + "验证签名异常", e);
			rmv.setRescode(ResultMsgVo.RESCODE_1000);// 验证签名失败
			return rmv;
		}

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			// 调用业务方法
			resultMap = kcodeService.queryResult(merchant, orderId);
			if (IsObjNullUtil.isEmpty(resultMap.get("orderId"))) {
				rmv.setRescode(ResultMsgVo.RESCODE_2005);
			} else {
				rmv.setRescode(ResultMsgVo.RESCODE_0000);
			}

			rmv.setData(resultMap);
		} catch (Exception e) {
			logger.error(logInfo + "查询K码发送情况异常" + "-" + orderId, e);

			resultMap.put("orderId", "");
			resultMap.put("userId", "");
			resultMap.put("mobile", "");
			resultMap.put("money", "");
			resultMap.put("cardNo", "");
			resultMap.put("createTime", "");

			rmv.setRescode(ResultMsgVo.RESCODE_3000);
			rmv.setData(resultMap);
		}

		logger.info(logInfo + "返回值为" + JSONObject.fromObject(rmv).toString());

		return rmv;
	}

	
	/**
	 * 
	 * @Description: 短信发送失败重发接口（根据订单号+手机号）
	 * @param request
	 * @param response
	 * @return
	 * @return ResultMsgVo<Object>
	 * @author ruXinChao
	 * @date 2016-9-14 下午5:16:47
	 */

	@RequestMapping(value = "/resendMsg", method = RequestMethod.POST)
	@ResponseBody
	public ResultMsgVo<Object> resendMsg(HttpServletRequest request,
			HttpServletResponse response) {
		logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>渲云接口查询K码发送结果<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
		ResultMsgVo<Object> rmv = new ResultMsgVo<Object>();

		// 读取request的流
		String reqString = LianlianPayUtil.readReqStr(request);

		/** 检验参数 **/
		if (StringUtils.isBlank(reqString)) {
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：未输入参数");
			return rmv;
		}

		JSONObject jsonObj=null;
		try {
			/** 获得参数以及检查参数 **/
			 jsonObj = JSONObject.fromObject(reqString);
		} catch (Exception e) {
			logger.info("校验参数失败，参数格式错误。实际参数"
					+ reqString);
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：缺少参数");
			return rmv;
		}

		List<String> keyList = Arrays.asList("merchant","mobile", "signType", "sign",
				"orderId");

		if (this.checkJsonKey(jsonObj, keyList)) {
			logger.info("校验参数失败，缺少参数应有参数{merchant,mobile,signType,sign,orderId}实际参数"
					+ reqString);
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：缺少参数");
			return rmv;
		}

		String merchant = jsonObj.getString("merchant");// 商户（xuanyun）
		String signType = jsonObj.getString("signType");// 签名类型（MD5）
		String sign = jsonObj.getString("sign");// 签名字符
		String orderId = jsonObj.getString("orderId");// 订单id
		String mobile = jsonObj.getString("mobile");// 手机号

		String logInfo = "K码发送失败重发接口" + orderId + "-";
		logger.info(logInfo + "1.请求参数" + reqString);

		logger.info(logInfo + "2.检测参数开始");

		/** 校验MD5签名 **/
		try {

			// 校验必填参数
			if (IsObjNullUtil.isEmpty(merchant, signType,mobile, sign, orderId)) {
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
				rmv.setmessage("参数校验失败：参数有空值");
				logger.info(logInfo + "返回值为"
						+ JSONObject.fromObject(rmv).toString());
				return rmv;
			}

			if (!"xuanyun".equals(merchant)) {
				logger.info(logInfo + "校验参数失败,商户错误，应为xuanyun" + reqString);
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
				rmv.setmessage("参数校验失败：渠道错误");
				return rmv;
			}
			
			if (!IsObjNullUtil.isMobileNO(mobile)) {
				logger.info(logInfo + "校验参数失败,手机号输入有误" + reqString);
				rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败、
				rmv.setmessage("参数校验失败：手机号格式错误");
				return rmv;
			}

			if (!Md5SignatureUtil.checkSign(reqString, null,
					kcodeService.getSecretKey(ChannelConstans.XY_CHANNEL_ID))) {// 22代表渲云的渠道id
				rmv.setRescode(ResultMsgVo.RESCODE_1000);// 验证签名失败

				logger.error(logInfo + "验签失败");
				logger.info(logInfo + "返回值为"
						+ JSONObject.fromObject(rmv).toString());
				return rmv;
			}
		} catch (Exception e) {
			logger.error(logInfo + "验证签名异常", e);
			rmv.setRescode(ResultMsgVo.RESCODE_1000);// 验证签名失败
			return rmv;
		}

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			// 调用业务方法
			
			
			String resultCode=kcodeService.resendMsg(logInfo,merchant, mobile, orderId);
			
			if (!ResultMsgVo.RESCODE_0000.equals(resultCode)) {
				rmv.setRescode(resultCode);
				logger.info(logInfo + "短信重发失败失败" + resultCode);
				logger.info(logInfo + "返回值为"
						+ JSONObject.fromObject(rmv).toString());
				return rmv;
			}
			
			
			resultMap = kcodeService.queryResult(merchant, orderId);
			if (IsObjNullUtil.isEmpty(resultMap.get("orderId"))) {
				rmv.setRescode(ResultMsgVo.RESCODE_2005);
			} else {
				rmv.setRescode(ResultMsgVo.RESCODE_0000);
			}

			rmv.setData(resultMap);
		} catch (Exception e) {
			logger.error(logInfo + "查询K码发送情况异常" + "-" + orderId, e);

			resultMap.put("orderId", "");
			resultMap.put("userId", "");
			resultMap.put("mobile", "");
			resultMap.put("money", "");
			resultMap.put("cardNo", "");
			resultMap.put("createTime", "");

			rmv.setRescode(ResultMsgVo.RESCODE_3000);
			rmv.setData(resultMap);
		}

		logger.info(logInfo + "返回值为" + JSONObject.fromObject(rmv).toString());

		return rmv;
	}

	
	
	/**
	 * 
	 * @Description: 校验jsonObj里的key是否存在,有一个不存在返回true，全存在返回false
	 * @param jsonObj
	 * @param keyList
	 * @return
	 * @return boolean
	 * @author ruXinChao
	 * @date 2016-9-23 上午9:38:09
	 */
	private boolean checkJsonKey(JSONObject jsonObj, List<String> keyList) {

		for (String string : keyList) {
			if (!jsonObj.containsKey(string)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * 
	 * @Description: 查询K码发送结果（内部自己使用）
	 * @param request
	 * @param response
	 * @return
	 * @return ResultMsgVo<Object>
	 * @author ruXinChao
	 * @date 2016-11-07 13:50:44
	 */

	@RequestMapping(value = "/queryResultByPhone")
	@ResponseBody
	public ResultMsgVo<Object> queryResultByPhone(HttpServletRequest request,
			HttpServletResponse response) {
		logger.info(">>>>>>>>>>>>>>>>>>>>>>>>>>渲云接口查询K码发送结果<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
		ResultMsgVo<Object> rmv = new ResultMsgVo<Object>();
		String phone=request.getParameter("phone");
		if (StringUtils.isBlank(phone)) {
			logger.info("校验参数失败，缺少参数应有参数{merchant, signType,sign,orderId}实际参数"
					+ phone);
			rmv.setRescode(ResultMsgVo.RESCODE_1001);// 参数校验失败
			rmv.setmessage("参数校验失败：缺少参数");
			return rmv;
		}

		String merchant = "";// 商户（xuanyun）

		String logInfo = "查询K码发送结果" + phone + "-";
		logger.info(logInfo + "1.请求参数" + phone);

		Map<String, Object> resultMap = new HashMap<String, Object>();
		try {
			// 调用业务方法
			resultMap = kcodeService.queryResultByPhone(merchant, phone);
			if (IsObjNullUtil.isEmpty(resultMap.get("orderId"))) {
				rmv.setRescode(ResultMsgVo.RESCODE_2005);
			} else {
				rmv.setRescode(ResultMsgVo.RESCODE_0000);
			}

			rmv.setData(resultMap);
		} catch (Exception e) {
			logger.error(logInfo + "查询K码发送情况异常" + "-" + phone, e);

			resultMap.put("orderId", "");
			resultMap.put("userId", "");
			resultMap.put("mobile", "");
			resultMap.put("money", "");
			resultMap.put("cardNo", "");
			resultMap.put("createTime", "");

			rmv.setRescode(ResultMsgVo.RESCODE_3000);
			rmv.setData(resultMap);
		}

		logger.info(logInfo + "返回值为" + JSONObject.fromObject(rmv).toString());

		return rmv;
	}
	
}
